home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / jpegtool.lha / JpegTool / jpegtool.rexx < prev   
OS/2 REXX Batch file  |  1999-03-09  |  14KB  |  477 lines

  1. /*
  2.   $VER: JpegToolGUI.rexx 1.0 (28.2.99) Nils Görs
  3. */
  4.  
  5. /* Informationen über das Ausgabefenster      */
  6. LeftBorder   = 10    /*Abstand linker Rand    */
  7. TopBorder    = 300   /*Abstand vom oberen Rand*/
  8. OutPutWidth  = 640   /*Breite des Fensters    */
  9. OutPutHeight = 150   /*Höhe des Fensters      */
  10.  
  11. StandardPath = "ram:"
  12.  
  13. OPTIONS RESULTS
  14.  
  15. PARSE ARG PubScreen
  16.  
  17. IF PubScreen == "?" THEN DO
  18.  OPTIONS PROMPT "PUBSCREEN/K: "
  19.  PARSE PULL PubScreen
  20. END
  21.  
  22.  
  23. CALL _InitAll
  24.  
  25. /*
  26. ** Beschreibung der Applikation
  27. */
  28. appname     = 'JpegToolGUI'
  29. applongname = 'JpegTool - ©99 by Nils Görs'
  30. appinfo     = 'graphical user interface for JpegTool'
  31. appversion  = '1.0'
  32. apprelease  = '1'
  33. appdate     = '28.2.99'
  34.  
  35. _maintags:
  36. windowtags = WindowID(1),
  37.              PubScreenName(PubScreen),
  38.              WindowBackfillFB,
  39.              WindowTitle(appname appversion),
  40.              QuickHelpOn(HelpBool),
  41.              BeginMenu('Project'),
  42.          MenuItemC('H_QuickHelp',100),
  43.              MenuItem('?_About',101) ItemBarlabel,
  44.              MenuItem('Q_Quit',102),
  45.              'HorizGroupA Space VertGroupA Space',
  46.                'LineArray',
  47.             'BeginLine',
  48.                 Text3('_From: ') 'TRAT_ID 1',
  49.                 StringGadget('',1) 'TRAT_Value 255',
  50.                 QuickHelp("specifies the images to convert"),
  51.                 GetFileButton(2),
  52.             'EndLine',
  53.         'SpaceS',
  54.             'BeginLine',
  55.                 Text3('_To: ') 'TRAT_ID 3',
  56.                 StringGadget('',3) 'TRAT_Value 255',
  57.                 QuickHelp("specifies the destination file"),
  58.                 GetFileButton(4),
  59.             'EndLine',
  60.         'SpaceS',
  61.             'BeginLine',
  62.                 Text3('_Destdatatype: ') 'TRAT_ID 5',
  63.                 StringGadget('',5) 'TRAT_Value 255',
  64.                 QuickHelp("Tells the program to create a datatypes object"NL"from a jpeg stream. To create an ilbm picture specify"NL"picture.datatype. This option requires picture datatype v43"NL"and datatypes.library v45! And, of course, the specified"NL"subclass of picturedt must be v43 compatible and provide an encoder."),
  65.                 GetEntryButton(6),
  66.             'EndLine',
  67.         'Space',
  68.             'BeginLine',
  69.                 Text3("_Quality") 'TRAT_ID 7',
  70.                 SliderGadget(1,100,75,7),
  71.                 QuickHelp("quality of the jpeg stream to create."),
  72.                 'Space',
  73.                 Text3('75%') 'TRAT_MinWidth 4 TRAT_ID 77',
  74.             'EndLine',
  75.         'SpaceS',
  76.             'BeginLine',
  77.                 Text3("_Smoothing") 'TRAT_ID 8',
  78.                 SliderGadget(0,100,0,8),
  79.                 QuickHelp("smoothing factor of the jpeg stream to create (0 = no smoothing)"),
  80.                 'Space',
  81.                 Text3('0%') 'TRAT_MinWidth 3 TRAT_ID 88',
  82.             'EndLine',
  83.         'SpaceS',
  84.             'BeginLine',
  85.                 Text3("Scalede_nom") 'TRAT_ID 9',
  86.                 SliderGadget(1,4,1,9),
  87.                 QuickHelp("scaling denominator when decompressing a jpeg image."NL"Denominators supported are 1 (default), 2, 4 and 8."NL"Eg. if you want to have an image that is halve of"NL"the size of the original one specify SD=2."),
  88.                 'Space',
  89.                 Text3('1') 'TRAT_MinWidth 2 TRAT_ID 99',
  90.             'EndLine',
  91.         'SpaceS',
  92.             'BeginLine',
  93.                 Text3("Scalenum") 'TRAT_ID 13',
  94.                 SliderGadget(1,1,1,13),
  95.                 QuickHelp("scaling numerator when decompressing a jpeg image."NL"The jpeg code only supports a value of 1 (default) currently."),
  96.                 'Space',
  97.                 Text3('1'),
  98.             'EndLine',
  99.         'Space',
  100.         'EndArray',
  101.         'HorizGroupAC',
  102.             'BeginLine',
  103.                     Text3("D_ctmethod: ") 'TRAT_ID 14',
  104.                     CycleGadget(DCTMETHOD,0,14),
  105.                     QuickHelp("allows to specify the dct method used for de-/encoding."NL"ISLOW: integer, slow, more accurate (default)."NL"IFAST: integer, fast, lessaccurate."NL"FLOAT: float, fast on fast machines, most accurate."),
  106.                 'SpaceB',
  107.                     Text3("_Blocksmoothing: ") 'TRAT_ID 10',
  108.                     CheckBox(10),
  109.                     QuickHelp("do block smoothing when decompressing."),
  110.                 'SpaceB',
  111.                     Text3("_Progressive: ") 'TRAT_ID 11',
  112.                     CheckBox(11),
  113.                     QuickHelp("create progressive jpeg."),
  114.                 'SpaceB',
  115.                     Text3("Qui_et: ") 'TRAT_ID 12',
  116.                     CheckBox(12),
  117.                     QuickHelp("suppresses any message except error messages."),
  118.                 'SpaceB',
  119.                     Text3("_Grayscale: ") 'TRAT_ID 15',
  120.                     CheckBox(15),
  121.                     QuickHelp("create grayscale image."),
  122.             'EndLine',
  123.         'EndGroup',
  124.         'Space',
  125.         Button("Con_vert",16),
  126.              'Space EndGroup Space EndGroup EndProject'
  127. /*
  128. ** Unterbrechungssignale
  129. */
  130.  
  131. SIGNAL ON break_c
  132. SIGNAL ON failure
  133. SIGNAL ON halt
  134. SIGNAL ON ioerr
  135. SIGNAL ON syntax
  136.  
  137. app = TR_CREATEAPP('TRCA_Name'     '"'appname'"',
  138.                    'TRCA_LongName' '"'applongname'"',
  139.                    'TRCA_Info'     '"'appinfo'"',
  140.                    'TRCA_Version'  '"'appversion'"',
  141.                    'TRCA_Release'  '"'apprelease'"',
  142.                    'TRCA_Date'     '"'appdate'"',
  143.                    'TAG_END')
  144.  
  145. IF app ~= '00000000'x THEN DO
  146.    window = TR_OPENPROJECT(app,windowtags)
  147.    WindowProject=C2D(window) /* zum Locken des Fensters bei About */
  148.    IF window ~= '00000000'x THEN DO
  149.       nummer = 0
  150.  
  151.       DO WHILE nummer = 0
  152.          CALL TR_WAIT(app,'')
  153.  
  154.          DO WHILE TR_HANDLEMSG(app,'event')
  155.  
  156. /******************
  157. *** CLOSEGADGET ***
  158. *******************/
  159.             IF event.trm_class = 'TRMS_CLOSEWINDOW' THEN nummer = -1
  160.  
  161.  
  162.     IF event.trm_class = 'TRMS_ACTION' THEN DO
  163.         SELECT
  164.             WHEN event.trm_id = 16 THEN CALL _Convert
  165.             WHEN event.trm_id = 2 THEN DO
  166.             infile = TR_GETATTRIBUTE(window,1,'TROB_String')
  167.             IF infile = " " THEN infile = "INFILE"
  168.                 IF _FileRequest(infile "Select source file") = 1 THEN DO
  169.                     Infile = filename.1
  170.                     CALL TR_SETATTRIBUTE(window,1,'TROB_String',Infile)
  171.                 END
  172.             END
  173.             WHEN event.trm_id = 4 THEN DO
  174.             outfile = TR_GETATTRIBUTE(window,3,'TROB_String')
  175.             IF outfile = " " THEN outfile = "OUTFILE"
  176.                 IF _FileRequest(outfile "Select destination file") = 1 THEN DO
  177.                     Outfile = filename.1
  178.                     CALL TR_SETATTRIBUTE(window,3,'TROB_String',Outfile)
  179.                 END
  180.             END
  181.             WHEN event.trm_id = 6 THEN DO
  182.                 NewDatatype = selectdatatypes()
  183.                 IF newdatatype ~= 0 THEN DO
  184.                     laenge=LENGTH(newDatatype)
  185.                     NewDataType=LEFT(NewDataType,Laenge-9)
  186.                     CALL TR_SETATTRIBUTE(window,5,'TROB_String',NewDataType)
  187.                 END
  188.             END
  189.  
  190.             WHEN event.trm_id  = 101 THEN CALL _About
  191.             WHEN event.trm_id  = 102 THEN DO
  192.                         Quit=TR_EasyRequest(app,"Really Quit?",,
  193.                                             "Yes|No","TREZ_Title Quit TREZ_LockProject" WindowProject)
  194.                         IF Quit == 1 THEN nummer=1
  195.                     END
  196.         OTHERWISE
  197.             NOP
  198.         END
  199.     END
  200.  
  201.     IF event.trm_class = 'TRMS_NEWVALUE' THEN DO
  202.         SELECT
  203.             WHEN event.trm_id = 7 THEN CALL TR_SETATTRIBUTE(window,77,'TRAT_Text',event.trm_data||"%")
  204.             WHEN event.trm_id = 8 THEN CALL TR_SETATTRIBUTE(window,88,'TRAT_Text',event.trm_data||"%")
  205.  
  206.             WHEN event.trm_id = 9 THEN DO
  207.                 IF event.trm_data = 4 THEN event.trm_data = event.trm_data * 2
  208.                 IF event.trm_data = 3 THEN event.trm_data = event.trm_data + 1
  209.                 CALL TR_SETATTRIBUTE(window,99,'TRAT_Text',event.trm_data)
  210.             END
  211.             WHEN event.trm_id = 100 THEN DO
  212.                 HelpBool = TR_GETATTRIBUTE(window,100,'TRAT_VALUE')
  213.                 CALL TR_SETATTRIBUTE(window,0,'TRWI_QuickHelp',HelpBool)
  214.             END
  215.         OTHERWISE
  216.             NOP
  217.         END
  218.     END
  219. /* ENDE */
  220.          END
  221.       END
  222.       CALL TR_CLOSEPROJECT(window)
  223.    END
  224.    CALL TR_DELETEAPP(app)
  225. END
  226. EXIT(0)
  227.  
  228. _FileRequest:
  229. PARSE ARG CommandPath title
  230.  
  231. IF commandpath == "INFILE" | commandpath == "OUTFILE" | commandpath = "" THEN commandpath = standardpath
  232.  
  233.     CommandPath = RXTR_PATHPART(CommandPath)
  234.     IF CommandPath = "" THEN commandpath = standardpath
  235.  
  236.             bool = ASL_RequestFile(window,filename,,
  237.                 "ASLFR_PubScreenName" PubScreen,
  238.                 "ASLFR_InitialPattern" PatternList,
  239.                 "ASLFR_DoPatterns" 1,
  240.                 "ASLFR_InitialDrawer" CommandPath,
  241.                 "ASLFR_TitleText" '"'||Title||'"')
  242. RETURN(bool)
  243.  
  244.  
  245. _Convert:
  246. Args = ""
  247.     InFile = TR_GETATTRIBUTE(window,1,'TROB_String')
  248.     OutFile = TR_GETATTRIBUTE(window,3,'TROB_String')
  249.     IF OutFile = "" | InFile = "" THEN RETURN
  250.  
  251.     DestDataType = TR_GETATTRIBUTE(window,5,'TROB_String')
  252.     IF DestDataType ~= "" THEN Args = "DTN="||Destdatatype
  253.  
  254.     Quality = TR_GETATTRIBUTE(window,7,'TRAT_Value')
  255.     IF Quality ~= 75 THEN Args = Args "Q="||Quality
  256.  
  257.     Smoothing = TR_GETATTRIBUTE(window,8,'TRAT_Value')
  258.     IF Smoothing ~= 0 THEN Args = Args "S="||Smoothing
  259.  
  260.     Scale = TR_GETATTRIBUTE(window,9,'TRAT_Value')
  261.     IF Scale ~= 1 THEN Args = Args "SD="||Scale
  262.  
  263.     wert = TR_GETATTRIBUTE(window,14,'TRAT_Value')+1
  264.     IF Wert ~= 1 THEN Args = Args "DCT="||DCTMETHOD.wert
  265.  
  266.     Block = TR_GETATTRIBUTE(window,10,'TRAT_Value')
  267.     IF Block = 1 THEN Args = Args "BS"
  268.  
  269.     Progressive = TR_GETATTRIBUTE(window,11,'TRAT_Value')
  270.     IF Progressive = 1 THEN Args = Args "P"
  271.  
  272.     GrayScale = TR_GETATTRIBUTE(window,15,'TRAT_Value')
  273.     IF GrayScale = 1 THEN Args = Args "GS"
  274.  
  275.     Quiet = TR_GETATTRIBUTE(window,12,'TRAT_Value')
  276.     IF Quiet = 1 THEN Args = Args "QUIET"
  277.  
  278.       CALL TR_LOCKPROJECT(window)
  279.     IF Quiet = 1 THEN ADDRESS COMMAND "jpegtool FROM="||InFile "TO="||OutFile Args
  280.     ELSE ADDRESS COMMAND "jpegtool FROM="||InFile "TO="||OutFile Args "<>CON:"LeftBorder"/"TopBorder"/"OutPutWidth"/"OutPutHeight"/converting/AUTO/CLOSE/SCREEN"PubScreen
  281.       CALL TR_UNLOCKPROJECT(window)
  282.     RETURN
  283.  
  284. /*
  285. ** Select datatypes
  286. */
  287. selectdatatypes:
  288.  
  289. datatypeswindowtags = ,
  290.    WindowID(2),
  291.    WindowPosition('TRWP_MOUSEPOINTER'),
  292.    WindowTitle('Select datatypes'),
  293.    WindowFlags('TRWF_NOESCCLOSE'),
  294.    PubScreenName(pubscreen),
  295.    'VertGroupA',
  296.       'Space',
  297.       'HorizGroupA',
  298.          'Space',
  299.          ListSS('datatypes',201,0,0),
  300.          'Space',
  301.       'EndGroup',
  302.       'Space',
  303.       'HorizSeparator',
  304.       'Space',
  305.       'HorizGroupA',
  306.          'Space',
  307.          ButtonR('_USE',298),
  308.          ButtonE('_CANCEL',299),
  309.          'Space',
  310.       'EndGroup',
  311.       'Space',
  312.    'EndGroup EndProject'
  313.  
  314.    datatypeswindow = TR_OPENPROJECT(app,datatypeswindowtags)
  315.  
  316.    IF datatypeswindow ~= '00000000'x THEN DO
  317.       CALL TR_LOCKPROJECT(window)
  318.  
  319.       quitdatatypeswindow = FALSE
  320.  
  321.       DO WHILE ~quitdatatypeswindow
  322.          CALL TR_WAIT(app,'')
  323.  
  324.          DO WHILE TR_HANDLEMSG(app,'event')
  325.             IF event.trm_class = 'TRMS_CLOSEWINDOW' THEN DO
  326.                quitdatatypeswindow = TRUE
  327.           selecteddatatypes = FALSE
  328.         END
  329.  
  330.             IF event.trm_class = 'TRMS_ACTION' THEN DO
  331.                IF event.trm_id = 298 THEN DO
  332.                   selecteddatatypes = datatypes.number
  333.                   quitdatatypeswindow = TRUE
  334.                END
  335.  
  336.                IF event.trm_id = 299 THEN DO
  337.                   quitdatatypeswindow = TRUE
  338.           selecteddatatypes = FALSE
  339.         END
  340.             END
  341.  
  342.             IF event.trm_class = 'TRMS_NEWVALUE' & event.trm_id = 201 THEN DO
  343.                number = event.trm_data+1
  344.  
  345.                IF BITAND(D2X(event.trm_qualifier),'0200'x) = '0200'x THEN DO
  346.                   selecteddatatypes = datatypes.number
  347.                   quitdatatypeswindow = TRUE
  348.                END
  349.             END
  350.          END
  351.       END
  352.  
  353.       CALL TR_CLOSEPROJECT(datatypeswindow)
  354.       CALL TR_UNLOCKPROJECT(window)
  355.    END
  356.  
  357.    RETURN(selecteddatatypes)
  358.  
  359. _InitAll:
  360. NL        = '0a'x
  361. TRUE        = 1
  362. FALSE        = 0
  363. HelpBool    = 0
  364. DCTMETHOD.0 = 3
  365. DCTMETHOD.1 = "ISLOW"
  366. DCTMETHOD.2 = "IFAST"
  367. DCTMETHOD.3 = "FLOAT"
  368.  
  369. PatternList = "#?(.jpg|.iff|.gif|.png)"    /* für Filerequester */
  370.  
  371.    /*
  372.    ** Open libs
  373.    */
  374.  
  375.    IF ~SHOW('LIBRARIES','tritonrexx.library') THEN
  376.       IF ~ADDLIB('tritonrexx.library',10,-30,0) THEN
  377.          quit('Cannot open tritonrexx.library!',10)
  378.  
  379.    IF ~SHOW(LIBRARIES,'rexxtricks.library') THEN
  380.       IF ~ADDLIB('rexxtricks.library',9,-30,38) THEN
  381.          quit('Cannot open rexxtricks.library!',10)
  382.  
  383.    IF ~SHOW('LIBRARIES','rexxsupport.library') THEN
  384.       IF ~ADDLIB('rexxsupport.library',9,-30,0) THEN
  385.          quit('Cannot open rexxsupport.library!',10)
  386.  
  387.    IF ~SHOW('LIBRARIES','rexxreqtools.library') THEN
  388.       IF ~ADDLIB('rexxreqtools.library',9,-30,0) THEN
  389.          quit('Cannot open rexxreqtools.library!',10)
  390.  
  391.    /*
  392.    ** Set current dir
  393.    */
  394.  
  395.    PARSE SOURCE . . . script .
  396.    progdir = PATHPART(script)
  397.  
  398.    booll = LENGTH(progdir)
  399.    booli= LASTPOS(":",progdir)
  400.    boolh= LASTPOS("/",progdir)
  401.  
  402.   IF booli <= booll THEN progdir2=progdir||"/"
  403.   IF boolh == 0 THEN progdir2=progdir||"/"
  404.  
  405.    CALL PRAGMA('D',progdir)
  406.  
  407. /* Gibt es einen Parameter für den Bildschirm. Wenn nicht, dann wird
  408.    der Screen auf dem defaultPubScreen geöffnet. */
  409.  
  410. IF PubScreen == "" THEN
  411.    PubScreen = RXTR_GETDEFAULTPUBSCREEN()
  412. CALL RXTR_PUBSCREENTOFRONT(PubScreen)
  413.  
  414. bool = RXTR_GETDIR("sys:classes/DataTypes","#?.datatype",datatypes,'FILES','NAME')
  415. IF bool = 0 THEN datatypes.0 = 0
  416.         ELSE CALL RXTR_QSORT(datatypes,,"NOCASE",,)
  417.  
  418. RETURN
  419.  
  420. /*******************************************************************************
  421. ** Info über das Programm anzeigen
  422. *******************************************************************************/
  423. _About:
  424.    CALL TR_AUTOREQUEST(app,window,PubScreenName(PubScreen),
  425.          BeginRequester('About','TRWP_CENTERDISPLAY'),
  426.             'VertGroupA',
  427.                'Space',
  428.                CenteredText3(appname appversion '('||appdate||') (C) 1999 by Nils Görs <N.Goers@Art-Line.de>'),
  429.                'SpaceS',
  430.                CenteredText(appinfo),
  431.                'Space',
  432.                'HorizSeparator',
  433.                'SpaceS',
  434.                CenteredText3("This application uses:"),
  435.                'Space',
  436.                 CenteredText("'JpegTool' (C) by Stephan Rupprecht <stephan.rupprecht@gmx.de>"),
  437.                'SpaceS',
  438.                'HorizSeparator',
  439.                'Space',
  440.                CenteredText3('This program is using the 'Triton GUI creation system''),
  441.                'SpaceS',
  442.                CenteredText("'Triton' is (C) by Stefan Zeiger <s.zeiger@laren.rhein-main.de>"),
  443.                'Space',
  444.                'HorizSeparator',
  445.                'Space',
  446.                CenteredText3("This program also use 'tritonrexx.library'"),
  447.                'SpaceS',
  448.                'HorizGroupSC',
  449.                   'Space',
  450.                   TextN("'tritonrexx.library' is (C) by Jürgen Kohrmeyer <j_kohrmeyer@wilam.north.de>") 'TRAT_Flags TRTX_NOUNDERSCORE',
  451.                   'Space',
  452.                'EndGroup',
  453.                'Space',
  454.             'EndGroup',
  455.             'BeginRequesterGads',
  456.             CenteredButtonRE("Thanks",10000),
  457.          'EndRequester')
  458.    RETURN
  459.  
  460. /*******************************************************************************
  461. ** Routine, die bei einer Unterbrechung des Scripts aufgerufen wird
  462. *******************************************************************************/
  463.  
  464. break_c:
  465. failure:
  466. halt:
  467. ioerr:
  468. syntax:
  469.    SAY '+++ Fehler' rc 'in Zeile' sigl '-' ERRORTEXT(rc)
  470.    SAY SOURCELINE(sigl)
  471.  
  472.    IF app ~= '00000000'x THEN
  473.       CALL TR_DELETEAPP(app)
  474.  
  475.    EXIT(10)
  476. /*EOS*/
  477.